package com.anquing.securitydemo.server.impl;

import com.anquing.securitydemo.server.MessageService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

/**
 * @author wangqq65
 * @since 2021/8/16 16:18
 */
@Service
public class MessageServiceImpl implements MessageService {

    // 已认证
//    @PreAuthorize("authenticated")
//    // 拥有USER角色
    @PreAuthorize("hasRole('USER')")
    // 拥有test权限
//    @PreAuthorize("hasAuthority('TEST')")
    @Override
    public String getMessage() {
        Authentication authentication = SecurityContextHolder.getContext()
                .getAuthentication();
        return "Hello " + authentication;
    }
}
